Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the AspnetUsersInRoles class.
	''' </summary>
	<Serializable> _
	Public Partial Class AspnetUsersInRolesCollection 
	Inherits ActiveList(Of AspnetUsersInRoles, AspnetUsersInRolesCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the aspnet_UsersInRoles table.
	''' </summary>
	<Serializable> _
	Public Partial Class AspnetUsersInRoles 
	Inherits ActiveRecord(Of AspnetUsersInRoles)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("aspnet_UsersInRoles", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarUserId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarUserId.ColumnName = "UserId"
                colvarUserId.DataType = DbType.Guid
                colvarUserId.MaxLength = 0
                colvarUserId.AutoIncrement = false
                colvarUserId.IsNullable = false
                colvarUserId.IsPrimaryKey = true
                colvarUserId.IsForeignKey = true
                colvarUserId.IsReadOnly = false
                
                
				colvarUserId.ForeignKeyTableName = "aspnet_Users"
                
                schema.Columns.Add(colvarUserId)
                
                Dim colvarRoleId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarRoleId.ColumnName = "RoleId"
                colvarRoleId.DataType = DbType.Guid
                colvarRoleId.MaxLength = 0
                colvarRoleId.AutoIncrement = false
                colvarRoleId.IsNullable = false
                colvarRoleId.IsPrimaryKey = true
                colvarRoleId.IsForeignKey = true
                colvarRoleId.IsReadOnly = false
                
                
				colvarRoleId.ForeignKeyTableName = "aspnet_Roles"
                
                schema.Columns.Add(colvarRoleId)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("aspnet_UsersInRoles",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("UserId")> _
        Public Property UserId As Guid 
			Get
				Return GetColumnValue(Of Guid)("UserId")
			End Get
		    
			Set
				SetColumnValue("UserId", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("RoleId")> _
        Public Property RoleId As Guid 
			Get
				Return GetColumnValue(Of Guid)("RoleId")
			End Get
		    
			Set
				SetColumnValue("RoleId", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
		
		
		
		
		
	    
	    #Region "ForeignKey Methods"
	    
		''' <summary>
		''' Returns a AspnetRoles ActiveRecord object related to this AspnetUsersInRoles
		''' </summary>
		Public Property AspnetRoles() As Data.AspnetRoles
			Get
				Return Data.AspnetRoles.FetchByID(Me.RoleId)
			End Get
			Set
				SetColumnValue("RoleId", Value.RoleId)
			End Set
		End Property
	    
		''' <summary>
		''' Returns a AspnetUsers ActiveRecord object related to this AspnetUsersInRoles
		''' </summary>
		Public Property AspnetUsers() As Data.AspnetUsers
			Get
				Return Data.AspnetUsers.FetchByID(Me.UserId)
			End Get
			Set
				SetColumnValue("UserId", Value.UserId)
			End Set
		End Property
	    
	    #End Region
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varUserId As Guid,ByVal varRoleId As Guid)
			Dim item As AspnetUsersInRoles = New AspnetUsersInRoles()
			
            item.UserId = varUserId
            
            item.RoleId = varRoleId
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varUserId As Guid,ByVal varRoleId As Guid)
			Dim item As AspnetUsersInRoles = New AspnetUsersInRoles()
		    
                item.UserId = varUserId
				
                item.RoleId = varRoleId
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared UserId As String = "UserId"
            
            Public Shared RoleId As String = "RoleId"
            
		End Structure
		#End Region
	End Class
End Namespace
